<template>
  <div class="dashboard-container">
    <div>
      <h2>作用域插槽</h2>
      <hr>
      <!-- 封装一个组件：显示一个人的姓名 -->
      <ShowName first-name="tom" last-name="green" />
      <!-- 基于子组件的数据定制插槽的内容：作用域插槽 -->
      <ShowName first-name="小刚" last-name="张">
        <template v-slot="{info}">
          {{ info.lname + ' ' + info.fname }}
        </template>
      </ShowName>
      <hr>
      <el-table :data="list">
        <el-table-column label="姓名" prop="name" />
        <el-table-column label="年龄" prop="age" />
        <el-table-column label="性别" prop="gender">
          <template v-slot="{row}">
            {{ row.gender === 1 ? '男' : '女' }}
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import ShowName from './components/ShowName.vue'

export default {
  name: 'Dashboard',
  components: { ShowName },
  // data必须是个函数，独立的
  data () {
    return {
      list: [{
        id: 1,
        name: '李四',
        age: 12,
        gender: 1
      }, {
        id: 2,
        name: '张三',
        age: 13,
        gender: 1
      }, {
        id: 1,
        name: 'TOM',
        age: 16,
        gender: 2
      }]
    }
  }
}
</script>

<style lang="scss" scoped>
.eye-cls {
  color: blue;
}
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
</style>
